package com.example.game.entity;

import java.awt.*;

public class Player {
    private int x;
    private int y;
    private int width = 50;
    private int height = 50;
    private int speed = 5;
    private boolean isJumping = false;
    private int jumpHeight = 150;
    private int initialY;
    private int verticalSpeed = 0;
    private boolean facingRight = true;
    
    public Player(int x, int y) {
        this.x = x;
        this.y = y;
        this.initialY = y;
    }
    
    public void moveLeft() {
        x -= speed;
        facingRight = false;
    }
    
    public void moveRight() {
        x += speed;
        facingRight = true;
    }
    
    public void jump() {
        if (!isJumping) {
            isJumping = true;
            verticalSpeed = -15;
        }
    }
    
    public void update() {
        if (isJumping) {
            verticalSpeed += 1; // Gravity
            y += verticalSpeed;
            
            // Check if landed
            if (y >= initialY) {
                y = initialY;
                isJumping = false;
                verticalSpeed = 0;
            }
        }
    }
    
    public void draw(Graphics g) {
        g.setColor(Color.BLUE);
        g.fillRect(x, y, width, height);
        
        // Draw gun
        g.setColor(Color.DARK_GRAY);
        if (facingRight) {
            g.fillRect(x + width, y + height/3, 20, 5);
        } else {
            g.fillRect(x - 20, y + height/3, 20, 5);
        }
    }
    
    public Rectangle getBounds() {
        return new Rectangle(x, y, width, height);
    }
    
    public boolean isFacingRight() {
        return facingRight;
    }
    
    public int getX() {
        return x;
    }
    
    public int getY() {
        return y;
    }
}
